#include <config.h>
#include <encoding_manager.h>
#include <string.h>

static int Utf16beisSupported(unsigned char *pucFileName)
{
	const char aStrUtf16beHead[] = {0xFE, 0xFF, 0};

	if(strncmp(aStrUtf16beHead, (const char *)pucFileName, 2) == 0)
	{
		return 1;
	}
	else
	{
		return 0;
	}
}

static int Utf16beGetCodeFrmBuffer(unsigned char *pucBufStart, unsigned char *pucBufEnd, unsigned int *pdwCode)
{
	if(pucBufStart + 1 < pucBufEnd)
	{
		*pdwCode = (((unsigned int)pucBufStart[0])<<8) + pucBufStart[1];
		return 2;
	}
	else
	{
		return 0;
	}
}


static T_EncodingOpr g_tUtf16beEncodingOpr = {
	.name = "utf16be",
	.iHeadLen    = 2,
	.isSupported = Utf16beisSupported,
	.GetCodeFrmBuffer = Utf16beGetCodeFrmBuffer,
};

int Utf16beRegister(void)
{
	AddFontOprForEncoding(&g_tUtf16beEncodingOpr, GetFontOpr("freetype"));
	AddFontOprForEncoding(&g_tUtf16beEncodingOpr, GetFontOpr("ascii"));
	return RegisterEncodingOpr(&g_tUtf16beEncodingOpr);
}



